package com.powerunion.datacollection.service;

import java.sql.Connection;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;

import com.powerunion.datacollection.common.SystemException;
import com.powerunion.datacollection.dao.DaoFactory;
import com.powerunion.datacollection.dao.UrgencyDao;
import com.powerunion.datacollection.model.Urgency;
import com.powerunion.util.log.LogHelper;

public class UrgencyManager {
	private static Logger logger = LogHelper.getInstance().getLogger(
			UrgencyManager.class);
	private UrgencyDao dao = null;

	public UrgencyManager() {
		super();
		this.dao = (UrgencyDao) DaoFactory.getInstance().getDao(
				UrgencyDao.class);
	}

	public boolean delete(String procId) throws Exception {
		//参数为空
		if(StringUtils.isEmpty(procId)) {
			String[] args = { "procId" };
			// 打印错误日志
			StringBuffer msglog = new StringBuffer(
					"empty invoke parameter procId NULL ");
			logger.error(msglog.toString());
			throw new SystemException("error.common.parameter.empty", args);
		}
		return this.dao.delete(procId);
	}
	
	public String save(Urgency urgency,Connection conn)  throws Exception {
		//参数为空
		if(urgency == null) {
			String[] args = { "urgency" };
			// 打印错误日志
			StringBuffer msglog = new StringBuffer(
					"empty invoke parameter urgency NULL ");
			logger.error(msglog.toString());
			throw new SystemException("error.common.parameter.empty", args);
		}
		//参数为空
		if(conn == null) {
			String[] args = { "conn" };
			// 打印错误日志
			StringBuffer msglog = new StringBuffer(
					"empty invoke parameter conn NULL ");
			logger.error(msglog.toString());
			throw new SystemException("error.common.parameter.empty", args);
		}
		return this.dao.save(urgency,conn);
	}
	
	public Urgency getBykey(String actId,Connection conn) throws Exception {
		//参数为空
		if(StringUtils.isEmpty(actId)) {
			String[] args = { "actId" };
			// 打印错误日志
			StringBuffer msglog = new StringBuffer(
					"empty invoke parameter actId NULL ");
			logger.error(msglog.toString());
			throw new SystemException("error.common.parameter.empty", args);
		}
		
		//参数为空
		if(conn == null) {
			String[] args = { "conn" };
			// 打印错误日志
			StringBuffer msglog = new StringBuffer(
					"empty invoke parameter conn NULL ");
			logger.error(msglog.toString());
			throw new SystemException("error.common.parameter.empty", args);
		}
		return this.dao.getBykey(actId,conn);
	}
	
}
